package com.blog.controller.user;

import com.blog.result.Result;
import com.blog.service.WorksService;
import com.blog.vo.CategoryVO;
import com.blog.vo.WorksVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userWorksController")
@RequestMapping("/user/Works")
@Slf4j
public class WorksController {

    @Autowired
    private WorksService worksService;


    @GetMapping("/worksById/{uid}/{isShow}")
    public Result<List<WorksVO>> worksById(
            @PathVariable("uid") Long uid,
            @PathVariable("isShow") Long isShow) {
        log.info("根据用户ID查询作品（查看展示的作品）：{}||{}", uid, isShow);
        List<WorksVO> list = worksService.getListWorksByID(uid, isShow);
        return Result.success(list);
    }
    @GetMapping("/AllWorksById/{uid}")
    public Result<List<WorksVO>> AllWorksById(
            @PathVariable("uid") Long uid) {
        log.info("根据用户ID查询作品：{}", uid);
        List<WorksVO> list = worksService.getAllListWorksByID(uid);
        return Result.success(list);
    }

    @GetMapping("/oneWorksById/{wid}")
    public Result<WorksVO> oneWorksById(
            @PathVariable("wid") Long wid) {
        log.info("根据作品ID查询作品：{}", wid);
        WorksVO worksVO = worksService.getOneWorksByID(wid);
        return Result.success(worksVO);
    }
    //获取作品的类别（传入作品ID）
    @GetMapping("/getCategoryByWorksID/{wid}")
    public Result<List<CategoryVO>> getCategoryByWorksID( @PathVariable("wid") Long wid) {
        log.info("获取作品的类别（传入作品ID）：{}", wid);
        List<CategoryVO> categoryVOList = worksService.getCategoryByWorksID(wid);
        return Result.success(categoryVOList);
    }

    @GetMapping("/getWorksTotal/{uid}")
    public Result getWorksTotal( @PathVariable("uid") Long uid) {
        log.info("获取类别总数（传入用户ID）：{}", uid);
        Long total = worksService.getWorksTotal(uid);
        return Result.success(total);
    }
}
